package com.webchat.search.controller;


import com.webchat.common.bean.APIPageResponseBean;
import com.webchat.common.enums.ESMessageTypeEum;
import com.webchat.common.helper.SessionHelper;
import com.webchat.rmi.search.SearchEngineClient;
import com.webchat.search.service.es.WebChatElasticSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/api/search")
public class SearchClientController implements SearchEngineClient {

    @Autowired
    private WebChatElasticSearchService webChatElasticSearchService;

    /**
     * 聊天消息搜索
     *
     * @param query 关键词
     * @param type  搜索内容：空代表聚合搜索，搜全部；可以置顶具体的消息类型（聊天、公众号文章、用户）
     * @see ESMessageTypeEum
     *
     * @param size
     * @return
     */
    @GetMapping("/query")
    public APIPageResponseBean query(@RequestParam(value = "q", required = false) String query,
                                     @RequestParam(value = "type", required = false) Integer type,
                                     @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                                     @RequestParam(value = "size", required = false, defaultValue = "10") Integer size) {
        String userId = SessionHelper.getCurrentUserId();
//        return webChatElasticSearchService.query(type, userId, query, page, size);
        return null;
    }
}
